#include <bits/stdc++.h>
using namespace std;

template <typename T>
struct cmp {
    bool operator()(const T& x, const T& y) { return y < x; }
};

int solve() {
    int n, m;
    cin >> n >> m;

    int a[n], b;
    vector<int> a1 = vector<int>(n), a2 = vector<int>(n);

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 0; i < n; i++) {
        cin >> b;
        if (b == 1)
            a1.push_back(a[i]);
        else
            a2.push_back(a[i]);
    }

    sort(a1.begin(), a1.end(), cmp<int>());
    sort(a2.begin(), a2.end(), cmp<int>());

    vector<int>::iterator p1 = a1.begin(), p2 = a2.begin();
    int asum = 0, bsum = 0;

    while (p1 != a1.end() && p2 != a2.end()) {
        if (asum >= m)
            return bsum;
        if (p1 == a1.end()) {
            asum += *p2;
            bsum += 2;
            p2++;
        } else if (p2 == a2.end()) {
            asum += *p1;
            bsum += 1;
            p1++;
        } else if (asum + *p1 >= m) {
            asum += *p1;
            bsum += 1;
            p1++;
        } else if (2 * *p1 >= *p2) {
            asum += *p1;
            bsum += 1;
            p1++;
        } else {
            asum += *p2;
            bsum += 2;
            p2++;
        }
    }
    if (asum >= m)
        return bsum;
    return -1;
}

int main() {
    int t;
    cin >> t;
    while (t-- > 0)
        cout << solve() << endl;
    return 0;
}